﻿using aier.business.logic;
using aier.dataaccess.model;
using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace aier.wx.api.selfhost.Controllers
{
   
    /// <summary>
    /// 筛查项目
    /// </summary>
    [RoutePrefix("api/ScreenItem")]
    public class ScreenItemController : ApiController
    {
        /// <summary>
        /// 日志
        /// </summary>
        public ILog log { get; set; }
        /// <summary>
        /// 筛查项目逻辑
        /// </summary>
        public ScreenItemBll screenitemBll { get; set; }

        /// <summary>
        /// 根据医院ID获取筛查项目
        /// </summary>
        /// <param name="hospitalId">医院ID</param>
        /// <returns></returns>
        public IHttpActionResult Get(string hospitalId)
        {
            
            try
            {
                if (!string.IsNullOrWhiteSpace(hospitalId))
                {
                    var screenitems = screenitemBll.GetScreenItemsByHospID(new Guid(hospitalId));
                    return Ok(screenitems.ToList());
                }

                return NotFound();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return new ApiErrorResult(ex.Message, Request);

            }
        }

        /// <summary>
        /// 获取所有筛查项目
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("GetScreenAllTeams")]
        public IHttpActionResult GetScreenAllTeams()
        {
            List<ScreenItemView> itemViews = screenitemBll.GetScreenAllTeams();
            return Ok<IEnumerable<ScreenItemView>>(itemViews);
        }

        /// <summary>
        /// 根据筛查项目名称查询当前筛查项目
        /// 原程序使用：getScreenteam
        /// </summary>
        /// <param name="name">筛查项目名称</param>
        /// <param name="ownerid">负责人ID</param>
        /// <param name="statecode">状态０：可用,２:停用</param>
        /// <returns></returns>
        public IHttpActionResult QueryScreenItem(string name, string ownerid, int statecode = 0)
        {
            try
            {
                if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(ownerid)) return NotFound();
                IEnumerable<ScreenItemView> screenitems = screenitemBll.QueryScreenItem(name, ownerid, statecode);

                return Ok<IEnumerable<ScreenItemView>>(screenitems);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return new ApiErrorResult(ex.Message, Request);
            }
        }

    }
}
